#############################################################################
# Copyright (c) 2009 Dmitry Grushin <dgrushin@gmail.com>.
#
# This file is part of clupower (cluster power manager utility)
#
# Clupower is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clupower is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clupower.  If not, see <http://www.gnu.org/licenses/>.
#
# Contributors:
#    Dmitry Grushin <dgrushin@gmail.com> - initial API and implementation
#############################################################################

$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'cpmonitor'

class TestMonitor < Test::Unit::TestCase

  def setup
    $settings_path = File.dirname(__FILE__)
    $settings_file = "settings.test3.yaml"

    Settings.instance.load

    File.delete(Utils.get_lock_file) if File.exist?(Utils.get_lock_file)
  end

  def test_serv1
    CPMonitor.instance.print_stats_message("--------- TEST MONITOR 1 ------------- ")
    # cluster size = 3
    20.times do |i|
      CPMonitor.instance.log_node_off("n1") if i % 2 == 0
      CPMonitor.instance.log_node_on("n1") if i % 2 != 0
      CPMonitor.instance.log_job_wait_time("j1", rand(100))
      CPMonitor.instance.log_job_wait_time("j2", rand(300))
      CPMonitor.instance.print_stats
      sleep 1
    end
  end

  def test_serv2
    CPMonitor.instance.print_stats_message("--------- TEST MONITOR 2 ------------- ")
    # cluster size = 3
    CPMonitor.instance.log_node_off("n1")
    10.times do |i|
      CPMonitor.instance.print_stats
      sleep 1
    end
    CPMonitor.instance.finish
  end

end
